package util.wikiXML.objectModel;

import java.util.LinkedList;
import java.util.List;

public abstract class WikiContainer {

	protected List elements = new LinkedList();
	public void setElements(List elements) {
		this.elements = elements;
	}

	protected StringBuffer value = new StringBuffer();

	public String getValue() {
		return value.toString();
	}

	public void setValue(String value) {
		this.value = new StringBuffer(value);
	}

	
	public void appendValue(String value){
			
		this.value.append(value);
	}
	public void addElement(Object obj) {
		// TODO Auto-generated method stub

		if (obj instanceof String && elements != null && elements.size() > 0) {
			Object last = elements.get(elements.size()-1);
			if (last instanceof StringBuffer) {
				((StringBuffer) (last)).append((String) obj);
			} else {
				elements.add(new StringBuffer((String) obj));

			}

			return;

		}
		elements.add(obj);
	}

	public List getElements() {
		// TODO Auto-generated method stub

		return elements;

	}

	public Object getLastElement() {
		// TODO Auto-generated method stub

		if (elements != null && elements.size() > 0)
			return elements.get(elements.size()-1);

		return null;
	}

	public void cleanMe() {
		WikiContainer temp;
		for (int i = 0; i < elements.size(); i++) {

			if (elements.get(i) instanceof WikiContainer) {
				temp = (WikiContainer) elements.get(i);
				temp.cleanMe();
			}
			temp = null;

		}
		value = null;

	}

}
